package org.terrier.matching.models.basicmodel;

import org.terrier.matching.models.Idf;
import org.terrier.utility.ApplicationSetup;

import uk.ac.gla.terrier.statistics.HKGammaFunction;

public class RLpdf extends BasicModel {
	/*
     * rayleigh pdf 
     */
    double rb = Double.parseDouble(ApplicationSetup.getProperty(
    		"distribution.parameter.0", "1"));
    double rayleighfirstpart = - 2 * Math.log(rb);

	@Override
	public String getInfo() {
		return "RLpdf_"+rb;
	}

	@Override
	public double score(double tf, double documentFrequency,
			double termFrequency, double keyFrequency, double documentLength) {
		double LogRayleighValue = 
			Math.log(tf) - (Math.pow(tf, 2) * (1 / (2 * Math.pow(rb, 2)))) + rayleighfirstpart;
		return -Idf.log(Math.exp(LogRayleighValue))*keyFrequency;
	}
	
	public void initModel(){
		String value = null;
		if ((value = ApplicationSetup.getProperty("distribution.parameter.0", "1d"))!=null){
			this.rb = Double.parseDouble(value);
		}
	}

}
